package com.com.datastructures.sort;

/**
 * Created with IntelliJ IDEA.
 * User: Ngo Lap Thanh
 * Date: 12/05/14
 * Time: 4:22 PM
 * To change this template use File | Settings | File Templates.
 */
public class IS {

    static int a [] = new int[6];
    static int swapCount=0;
    static {
        int b [] = {6,5,4,3,2,1};
        a = b;
    }
    public static void main(String[] args){
        printData();
        insertionSort();
        printData();
    }
    //    static void selectionSort(){
//
//	for(int i=1;i<a.length;i++){
//	int j=i;
//	while( j>0 && (a[j-1]>a[j])){
//	int temp = a[j-1];
//	a[j-1] = a[j];
//	    a[j] = temp;
//	    j--;
//	}
//	}
//
//	}
    public static void insertionSort(){
       for(int i=1;i<a.length;i++){
           int temp = a[i];
           int j = i;
           while(j>0 && temp<a[j-1]){
               swapCount++;
               a[j] = a[j-1];
               j--;
           }
           a[j] = temp;
       }
    }

    static void swap(int a1 ,int b1){
        swapCount++;
        int temp = a[a1];
        a[a1] = a[b1];
        a[b1] = temp;
    }

    static void printData(){
        System.out.print("\nItems: ");
        for(int i: a){
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.println("Swap Count: "+swapCount);
    }

}
